
from aip import AipImageClassify
import os
import cv2

"""
    APPID AK SK
"""
# 在百度云创的实例应用 获取的三个参数填写到下面
APP_ID = '21316511'
API_KEY = 'gNe4RDL2dVhgtIMlVYT61Lmy'
SECRET_KEY = 'T4PfhdHTrM4y1Pj5al7M8SAnp6te7tG1'
client = AipImageClassify(APP_ID, API_KEY, SECRET_KEY)

# 打开图片文件并读取二进制图片信息
def get_file_content(file_path):
    with open(file_path, 'rb') as f:
        return f.read()



# image = get_file_content('image/34.jpg')

# image=cv2.imread('image/34.jpg',cv2.IMREAD_GRAYSCALE)


"""
    调用车辆识别
"""
# {"top_num": 1} 表示返回的多个车型中的第一个

# 调用client对象的carDectect方法
# print(client.carDetect(image))
# print(client.carDetect(image,options={"top_num": 1})["color_result"])
# print(client.carDetect(image, options={"top_num": 1})["result"][0]["name"])

def chexing_get(path):

    img=get_file_content(path)
    # img=cv2.imread(path,1)
    color=client.carDetect(img,options={"top_num":1})["color_result"]
    name=client.carDetect(img, options={"top_num": 1})["result"][0]["name"]
    leibie=client.advancedGeneral(img,options={"top_num": 1})["result"][0]["keyword"]
    return leibie,color,name




if __name__ == "__main__":
    # 绝对地址，记得改一下 好的 好的
    # 'C:\\Users\\19372\\PycharmProjects\\untitled1\\static\\images\\5.jpg'
    leibie, color, name=chexing_get('C:\\Users\\19372\\Desktop\\5.jpg')
    print(leibie, color, name)



# print(client.carDetect(image, options={"top_num": 1})["result"][0]["name"])
# string=(client.carDetect(image, options={"top_num": 1})["result"][0]["name"])
# print(string)
# string=[]
# dir=("C:\\Users\\19372\\Desktop\\images\\images\\pictures")
# dirs = os.listdir("C:\\Users\\19372\\Desktop\\images\\images\\pictures")
# 输出所有文件和文件夹
# for img in dirs:
#     if not os.path.isdir(img):
#         img_path = os.path.join(dir, img)
#         image = get_file_content(img_path)
#         strs = (client.carDetect(image, options={"top_num": 1})["result"][0]["name"])
#         string.append(strs)
#
#
# print(string)



# for i in range(len(dir)):
#     # 获取目录的路径
#     img_temp_dir = os.path.join(img_dir, str(dir[i]))
#     # 获取该目录下所有的文件
#     img_list = os.listdir(img_temp_dir)
#     # 遍历所有的文件名称
#     for img_name in img_list:
#         # 判断文件是否为目录,如果为目录则不处理
#         if not os.path.isdir(img_name):
#             # 获取图片的路径
#             img_path = os.path.join(img_temp_dir, img_name)